package servlet;

import com.alibaba.fastjson2.JSON;
import dto.RentDto;
import entity.Rent;
import service.RentService;
import service.impl.RentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/index")
public class Index extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/json;charset=utf-8");
        RentService rentService=new RentServiceImpl();
        List<Rent> findall = rentService.findall();
        PrintWriter out = resp.getWriter();
        RentDto rentDto=new RentDto("200","查询成功",findall);
        out.write(JSON.toJSONString(rentDto));
    }
}
